package com.typing.battle.activity;

import android.app.Activity;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.LinearLayout.LayoutParams;

import com.typing.battle.listener.OnDataSyncCompleteListener;
import com.typing.battle.util.KDialog;
import com.typing.battle.util.KLog;
import com.typing.battle.value.ServerComunicationDTO;

/**
 * 
 * @author kyungmo.no
 *	모든 엑티비티는 이 클래스를 상속받는다.
 *	모든 엑티비티의 통합 컨트롤을 위하여...
 */

public abstract class TypingBattleRootActivity extends KDialog implements OnDataSyncCompleteListener{
	
	public final static LayoutParams params_MM = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
	public final static LayoutParams params_WW = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	public final static LayoutParams params_MW = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
	

	public final static int ACTIVITY_FEATURED = 1010;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		KLog.d(this, "onCreate");
		super.onCreate(savedInstanceState);
		//초기화.
//		requestWindowFeature(Window.FEATURE_NO_TITLE);
//		DisplayMetrics outMetrics = new DisplayMetrics();
//		getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
//		Util.dpip = outMetrics.density;
//		Util.log("dpip="+Util.dpip);
//		
//		Util.addActivity(this);
//		if (Util.DEBUG)  {
//			Util.log("Build.VERSION:"+ Util.getPackageVersion(this, getPackageName()));
//			Util.log("Build.BRAND:"+ Build.BRAND);
//			Util.log("Build.MANUFACTURER:"+ Build.MANUFACTURER);
//			Util.log("Build.MODEL:"+ Build.MODEL);
//			Util.log("Build.DISPLAY:"+ Build.DISPLAY);
//			Util.log("Build.HARDWARE:"+ Build.HARDWARE);
//			Util.log("Build.PRODUCT:"+ Build.PRODUCT);
//			
//			Util.log("Locale.getDefault().getCountry():"+Locale.getDefault().getCountry() );
//			Util.log("Locale.getDefault().getDisplayCountry():"+Locale.getDefault().getDisplayCountry() );
//			Util.log("Locale.getDefault().getDisplayLanguage():"+Locale.getDefault().getDisplayLanguage() );
//			Util.log("Locale.getDefault().getLanguage():"+ Locale.getDefault().getLanguage() );
//			
//		}
	}
	@Override
	public void onConfigurationChanged(Configuration newConfig) {
		super.onConfigurationChanged(newConfig);
	}
	@Override
	protected void onResume() {	
		KLog.d(this, "onResume");
		super.onResume();
	}
	@Override
	protected void onPause() {
		KLog.d(this, "onPause");
//		Util.log("RootActivity onPause :: "+isOnPause);
		super.onPause();
	}
	@Override
	protected void onRestart() {
		KLog.d(this, "onRestart");
		super.onRestart();
	}
	@Override
	protected void onStop() {
		KLog.d(this, "onStop");
		super.onStop();
	}
	@Override
	public void onBackPressed() {
		KLog.d(this, "onBackPressed");
		super.onBackPressed();
	}
	
	@Override
	public void onSyncComplete(int resultCode) {
		
	}
	@Override
	public void onSyncComplete(int resultCode, ServerComunicationDTO dto,
			Object resultObj) {
		
	}
	
	public void finish() {
//		Util.log("RootActivity finish :: "+isOnPause);
		closeProgress(this);
		closeDialog(this);
		super.finish();
	}
	
	
	public void showKeyboard(final boolean isShow, final EditText txt) {
		new Handler() {
			public void handleMessage(Message msg) {
				InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
		    	if (isShow) {
		    		imm.showSoftInput(txt, 0); 
		    	} else {
		    		imm.hideSoftInputFromWindow(txt.getWindowToken(),0);  
		    	}
			}
		}.sendEmptyMessageDelayed(1, 500);
    }
	/**
	 * 안드로이드 버전이 4.0.0 이상인지 확인한다.
	 * @return
	 */
	public static boolean isICS() {
		if (Build.VERSION.SDK_INT>13) return true;
		return false;
	}	
}